Repository navigation
test: restore working directory before removing tempdir in helper.test - #931
Open
SameRainbows wants to merge 1 commit into
Open
SameRainbows wants to merge 1 commit into
SameRainbows wants to merge 1 commit into
Conversation
In test/helper.test.js, fs.promises.rm(testdir) was registered in t.after before process.chdir(cwd). Because node:test runs t.after callbacks in registration order, the directory removal was attempted while process.cwd() was still set to testdir. On Windows, attempting to remove the current working directory fails with EBUSY/EPERM, which caused the teardown to fail and left the process in testdir, breaking subsequent test cases that rely on repository-relative paths. Moving process.chdir(cwd) before the rm call ensures the working directory is restored first, allowing tempdir cleanup to succeed cleanly. Signed-off-by: SameRainbows <avveralabs@gmail.com>
3 of 4 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In
test/helper.test.js,fs.promises.rm(testdir)was registered int.afterbeforeprocess.chdir(cwd). Becausenode:testexecutest.afterhooks in registration order, directory removal was attempted whileprocess.cwd()was still set totestdir.On Windows, attempting to delete the active working directory fails with
EBUSY. The rejection aborted teardown and leftprocess.cwd()pointing at the temp folder, which caused subsequent tests intest/helper.test.js(such assetting plugin options) to fail when looking up./examples/plugin-with-custom-options.js.Moving
process.chdir(cwd)ahead offs.promises.rm(testdir)inside a singlet.afterblock ensures the working directory is restored before the temp directory is removed.Validation
node --test test/helper.test.js: all 10 tests pass cleanly on Windows (previously failed at test 2).npm run lint: clean with 0 warnings or errors.